package com.bjpowernode.rbac.web.interceptor;

import com.bjpowernode.rbac.entity.Employee;
import com.bjpowernode.rbac.util.UserContext;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author jy
 * @version 1.0
 * @date 2022/2/10 21:27
 */
@Component
public class CheckLoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        Employee employee = UserContext.getEmployee();
        if (employee != null){
            return true;
        }

        response.sendRedirect("/login.html");
        return false;
    }
}
